package com.explorati.interview.interview.chapterThree;

public class Variable {

	private int i = 5;
	static double a = 321.421;

	{
		System.out.println("成员变量i = " + i);
		int i = 1;
		System.out.println("初始化块中i = " + i);
	}

	// 静态变量是类的，所以报错
	// {
	// static double a = 99.99;
	// }

	public void getI(int i) {
		// 全局变量 i = 5
		System.out.println("全局变量i = " + i);
		i = 0;
		// 将局部变量赋给全局i = 参数i
		System.out.println("局部变量赋值后i = " + i);
	}

	public void getA(double a) {
		System.out.println("静态变量a = " + this.a);
		this.a = a;
		System.out.println("局部变量赋值后的a = " + this.a);
		Variable.a = 2000;
		System.out.println("静态变量a赋值2000后 a = " + Variable.a);
	}

	public static void main(String[] args) {
		Variable v = new Variable();
		System.out.println("最初成员变量i = " + v.i);
		System.out.println("最初静态变量a = " + v.a);
		v.getI(9);
		System.out.println("调用完方法之后全局变量i = " + v.i);
		v.getA(0.001);
		System.out.println("调用完方法之后静态变量a = " + v.a);
	}
	/*
	 * 预计输出结果为：
	 * 成员变量i = 5
	初始化块中i = 1
	最初成员变量i = 5
	最初静态变量a = 321.421
	全局变量i = 9
	局部变量赋值后i = 0
	调用完方法之后全局变量i = 5
	静态变量a = 321.421
	局部变量赋值后的a = 0.001
	静态变量a赋值2000后 a = 2000.0
	调用完方法之后静态变量a = 2000.0
	 * 
	 */

}
